/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.thienloc.omap.session;

import com.thienloc.omap.entity.KeoChauAu;
import java.util.ArrayList;
import java.util.List;
import org.slf4j.LoggerFactory;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.NoResultException;
import javax.persistence.PersistenceContext;
import javax.persistence.TypedQuery;

/**
 *
 * @author GiangLT
 */
@Stateless
public class KeoChauAuFacade extends AbstractFacade<KeoChauAu> {

    @PersistenceContext(unitName = "omapPU")
    private EntityManager em;

    @Override
    protected EntityManager getEntityManager() {
        return em;
    }

    public KeoChauAuFacade() {
        super(KeoChauAu.class);
    }

    public List<KeoChauAu> findByMatchId(int id) {
        List<KeoChauAu> result = new ArrayList<KeoChauAu>();
        try {
            TypedQuery<KeoChauAu> q = em.createQuery("SELECT b FROM KeoChauAu b WHERE b.idTranDau.id=:id", KeoChauAu.class);
            q.setParameter("id", id);
            result = q.getResultList();
            return result;
        } catch (NoResultException ex) {
            return null;
        } catch (Exception ex) {
            LoggerFactory.getLogger(KeoChauAuFacade.class.getName()).error("", ex);
        }
        return result;
    }
}
